package com.hyz.controller;

import client.UserClient;
import com.hyz.pojo.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import pojo.ResponseResult;

import java.util.HashMap;
import java.util.Map;
import java.util.Objects;

@RestController
public class Varify {
    @Autowired
    private UserClient userClient;
    @PostMapping("/varifiying")
    public ResponseResult<Object> varifiying(@RequestBody Account account){
        Map<Long,String> rightsUrl = new HashMap<>();

        //配置响应数据集合
        rightsUrl.put(0L , "/index.html");
        rightsUrl.put(1L , "/pages/assetManager/assetManager.html");
        rightsUrl.put(2L , "/pages/repoManager/repoManager.html");
        rightsUrl.put(3L , "/pages/assetApplicant/assetApplication.html");
        rightsUrl.put(4L , "/pages/operations/operations.html");
        rightsUrl.put(5L , "/pages/approval/approval.html");
        rightsUrl.put(6L , "/pages/information/information.html");
        rightsUrl.put(7L , "/pages/chargeLeader/chargeLeader.html");
        rightsUrl.put(8L , "/pages/financial/financial.html");
        rightsUrl.put(9L , "/admin.html");
        /*
        -----权限集合-----
        0-无权限
        1-资产管理员
        2-仓库管理员
        3-业务申请人
        4-运维人员
        5-部门审批经理
        6-信息管理部经理
        7-分管经理
        8-财务经理
        9-超级管理员
         */

        ResponseResult<Boolean> booleanResponseResult = userClient.checkLogin(account.getUsername(), account.getPassword(), account.getRightsId());
        Map<String,String> resultUrl = new HashMap<>();
        System.out.println("account = " + account);
        if(booleanResponseResult.getData()){
            resultUrl.put("result",rightsUrl.get(account.getRightsId()));
            return new ResponseResult<>(200,"登录成功",resultUrl);
        }else {
            resultUrl.put("result",rightsUrl.get(0L));
            return new ResponseResult<>(400,"登录失败",resultUrl);
        }
    }
}
